package com.itqf.service.impl;

import com.itqf.entity.Product;
import com.itqf.mapper.ProductDao;
import com.itqf.service.ProductService;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import javax.annotation.Resource;
import java.util.List;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/9/30
 * @Time: 上午11:11
 */
//@Component   通用
//@Service(value="productServiceImpl")  //<bean id="productDaoImpl" class="xxx.ProductServiceImpl">
@Component
//@Scope("singleton")
//可以写到方法前  也可以写到类的前面，代表所有方法都走事务
@Transactional(isolation = Isolation.DEFAULT,propagation = Propagation.REQUIRED)  // <tx:method name="">

public class ProductServiceImpl implements ProductService {
    //依赖dao(mapper)
    @Resource //按照名字注入
    private ProductDao productDao;

    @Value("spring的注解")   //注入简单类型（8大基本数据类型和String,Date）
    private   String name;

    public  ProductServiceImpl(){
        System.out.println("ProductServiceImpl.....");
    }
    public ProductDao getProductDao() {
        return productDao;
    }

    public void setProductDao(ProductDao productDao) {
        this.productDao = productDao;
    }

    @Override
    public List<Product> findAll() {
        System.out.println(name+"----name");
        return productDao.findAll();
    }


    @Override
    public int update(Product product) {

        int i =  productDao.update(product);
        int k=10/0;

        return  i;
    }

    @PostConstruct
    public   void init(){

    }

    @PreDestroy
    public   void destory(){

    }



}
